from django.db import models
from django.utils import timezone

class Schedule(models.Model):
    route_number = models.CharField(max_length=50, verbose_name='线路编号')
    start_station = models.CharField(max_length=100, verbose_name='起始站')
    end_station = models.CharField(max_length=100, verbose_name='终点站')
    departure_time = models.TimeField(verbose_name='发车时间')
    estimated_duration = models.IntegerField(verbose_name='预计行程时间(分钟)')
    bus_plate = models.CharField(max_length=20, verbose_name='车牌号')
    price = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='票价')
    created_by = models.ForeignKey('users.User', on_delete=models.CASCADE, verbose_name='创建人')
    created_at = models.DateTimeField(default=timezone.now, verbose_name='创建时间')
    is_active = models.BooleanField(default=True, verbose_name='是否有效')

    class Meta:
        verbose_name = '班次'
        verbose_name_plural = '班次'
        ordering = ['departure_time']

    def __str__(self):
        return f"{self.route_number} - {self.start_station}到{self.end_station}"